﻿

layui.use(function () {
    var table = layui.table;
    var form = layui.form;
    var $ = layui.jquery;

    var code = Math.floor(Math.random() * 100000) + 1000000;
    $("#warehouseCode").val(code);
    console.log(code);

    var token = localStorage.getItem("token");

 

    form.on('submit(demo-verify)', function (data) {
        var field = data.field; // 获取表单字段值
        var fied = {
            department : field.department,
            warehouseName: field.warehouseName,
            warehouseCode: field.warehouseCode,
            warehouseType: field.warehouseType,
            RentalTime: field.RentalTime,
            Waddress: field.Waddress,
            Wcontact: field.Wcontact,
            Wphone: field.Wphone,
            Area: field.Area,
            Token: token
        }
        console.log(fied);
        $.ajax({
            url: '/Foundation/AddWarehouseInfo',
            type: 'POST',
            data: fied,
            success: function (res) {
                var s = JSON.parse(res);
                if (s.data > 0) {
                    layer.msg('添加成功', { icon: 1 }, function () {
                        location.href = "/Foundation/GetStorehouseList";
                    });
                } if (s.data == -2) {
                    layer.msg('库位编号已存在', { icon: 2 }, function () {
                        location.reload();
                    });
                }
                if (s.data == -1) {
                    layer.msg("重名了哦！");
                    return;
                }
            }
        })

        return false; // 阻止默认 form 跳转
    });
   

})





